// Copyright 2012 ESRI
//
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
//
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
//
// See the use restrictions at http://help.arcgis.com/en/sdk/10.0/usageRestrictions.htm
//

#import "CustomLayerViewController.h"
#import "TianDiTuWMTSLayer.h"
@implementation CustomLayerViewController

@synthesize mapView=_mapView;


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // 设置ClientID（去除地图上的水印）
    [AGSRuntimeEnvironment setClientID:@"L8zvYbPtXBtrHJ26" error:nil];
    
	NSError* err;
    ///* sr:Mercator(102100)
    //TianDiTuWMTSLayer* TianDiTuLyr = [[TianDiTuWMTSLayer alloc]initWithLayerType: TIANDITU_IMAGE_MERCATOR LocalServiceURL:nil error:&err];
    //TianDiTuWMTSLayer* TianDiTuLyr_Anno = [[TianDiTuWMTSLayer alloc]initWithLayerType:TIANDITU_VECTOR_ANNOTATION_CHINESE_2000 LocalServiceURL:nil error:&err];
    
    TianDiTuWMTSLayer* TianDiTuLyr      = [[TianDiTuWMTSLayer alloc]initWithLayerType: TIANDITU_VECTOR_MERCATOR                     LocalServiceURL:nil error:&err];
    TianDiTuWMTSLayer* TianDiTuLyr_Anno = [[TianDiTuWMTSLayer alloc]initWithLayerType: TIANDITU_VECTOR_ANNOTATION_CHINESE_MERCATOR  LocalServiceURL:nil error:&err];
    
    //TianDiTuLyr.delegate = self;
    
    //NSLog(@"tianditu图层url:%@"，TianDiTuLyr);
    
    
    /* sr:CGCS2000(4490)
     TianDiTuWMTSLayer* TianDiTuLyr = [[TianDiTuWMTSLayer alloc]initWithLayerType:TIANDITU_VECTOR_2000 LocalServiceURL:nil error:&err];
     TianDiTuWMTSLayer* TianDiTuLyr_Anno = [[TianDiTuWMTSLayer alloc]initWithLayerType:TIANDITU_VECTOR_ANNOTATION_CHINESE_2000 LocalServiceURL:nil error:&err];
    */

    /* localhost service,eg:"http://t0.tianditu.cn/vec_c/wmts"
    NSURL *localService = [NSURL URLWithString:@"http://t0.tianditu.cn/vec_c/wmts"];
     TianDiTuWMTSLayer* TianDiTuLyr = [[TianDiTuWMTSLayer alloc]initWithLayerType:TIANDITU_VECTOR_MERCATOR LocalServiceURL:localService error:&err];
     TianDiTuWMTSLayer* TianDiTuLyr_Anno = [[TianDiTuWMTSLayer alloc]initWithLayerType:TIANDITU_VECTOR_ANNOTATION_CHINESE_MERCATOR LocalServiceURL:localService error:&err];
     */
    
	//If layer was initialized properly, add to the map
	if(TianDiTuLyr!=nil && TianDiTuLyr_Anno != nil){
		[self.mapView addMapLayer:TianDiTuLyr       withName:@"TianDiTu Layer"];
        [self.mapView addMapLayer:TianDiTuLyr_Anno  withName:@"TianDiTu Annotation Layer"];
        
        

	}else{
		//layer encountered an error
		NSLog(@"Error encountered: %@", err);
	}
    
//    NSURL *url = [NSURL URLWithString:@"http://192.168.220.122:6080/arcgis/rest/services/chinabounds/MapServer"];
//    
//    AGSDynamicMapServiceLayer *dyMapServiceLayer = [[AGSDynamicMapServiceLayer alloc]initWithURL:url];
//    
//    dyMapServiceLayer.opacity = 0.8;
//    
//    
//    [self.mapView addMapLayer:dyMapServiceLayer withName:@"test"];
    
    
}

-(void)layerDidLoad:(AGSLayer *)layer{
    
    AGSEnvelope *env = [self.mapView maxEnvelope];
    
    NSLog(@"当前地图范围是：%@", env);
}



@end
